package com.team7.system.controller;

import com.team7.common.entity.Role;
import com.team7.common.vo.CommonResult;
import com.team7.common.vo.RoleVo;
import com.team7.common.vo.UserRoleVo;
import com.team7.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: team7-Object
 * @description:
 * @author: 杨海涛
 * @create: 2021-10-20 18:56
 **/
@RestController
@RequestMapping("/system/role")
@Api("角色表的api接口")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @ApiOperation("根据userId查询角色")
    @GetMapping("/findRoleByUserId/{userId}")
    public CommonResult findRoleByUserId(@PathVariable String userId) {
        //System.out.println(userId+"000000000000");
        return roleService.findRoleByUserId(userId);

    }

    @ApiOperation("分页查找角色信息")
    @PostMapping("findRoleByPage/{page}/{limit}")
    public CommonResult findRoleByPage(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit,@RequestBody RoleVo roleVo){
        return roleService.findRoleByPage(page,limit,roleVo);

    }


    @ApiOperation("根据角色名称来查询角色，分页")
    @PostMapping("findRoleByRoleName/{page}/{limit}")
    public CommonResult findRoleByRoleName(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, @RequestBody RoleVo roleVo){
        return roleService.findRoleByRoleName(page,limit,roleVo);

    }

    @ApiOperation("添加/修改角色信息")
    @PostMapping("addOrUpdateRole")
    public CommonResult addOrUpdateRole(@RequestBody Role role){
        return roleService.addOrUpdateRole(role);
    }

    @ApiOperation("删除角色信息")
    @DeleteMapping("deleteRoleById/{roleid}")
    public CommonResult deleteRoleById(@PathVariable("roleid") String roleid){
        return roleService.deleteRoleById(roleid);
    }

    @ApiOperation("通过id修改角色状态")
    @PostMapping("updateRoleStatusById/{id}/{deleted}")
    public CommonResult updateRoleStatusById(@PathVariable("id")String id,@PathVariable("deleted")Integer deleted){
        return roleService.updateRoleStatusByid(id,deleted);

    }

    @ApiOperation("分配用户角色")
    @PostMapping("fenUserRole")
    public CommonResult fenUserRole(@RequestBody UserRoleVo userRoleVo){
        return roleService.fenUserRole(userRoleVo);

    }



}
